﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>角色管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="~/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="~/layuiadmin/style/admin.css" media="all">
</head>
<body>

    <div class="layui-card layadmin-header">
        <div class="layui-breadcrumb" lay-filter="breadcrumb">
            <a lay-href="">主页</a>
            <a><cite>角色</cite></a>
            <a><cite>角色列表</cite></a>
        </div>
    </div>

    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <!---搜索条件 begin--->
                    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">角色名</label>
                                <div class="layui-input-block">
                                    <input type="text" name="rolename" placeholder="请输入" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <button class="layui-btn layuiadmin-btn-admin" lay-submit="" lay-filter="app-search">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    <!----搜索条件 end--->
                    <div class="layui-card-body">
                        <div style="padding-bottom: 10px;">
                            @if ((bool)ViewData[PageCode.PAGE_Button_Add])
                            {
                                <a class="layui-btn layuiadmin-btn-admin" data-type="add" href="/role/edit">添加</a>
                            }
                        </div>
                        <table class="layui-hide" id="app-table" lay-filter="app-table"></table>
                        <script type="text/html" id="status">
                            {{# if(d.isActive === true){ }}
                            <span class="layui-btn layui-btn-primary layui-btn-xs">启用</span>
                            {{# } }}
                            {{# if(d.isActive === false ){ }}
                            <span class="layui-btn layui-btn-danger layui-btn-xs">禁用</span>
                            {{# } }}
                        </script>
                        <script type="text/html" id="app-table-bar">
                            @if ((bool)ViewData[PageCode.PAGE_Button_Edit])
                            {
                                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                            }
                            @if ((bool)ViewData[PageCode.PAGE_Button_Authorize])
                            {
                                <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="autho"><i class="layui-icon layui-icon-edit"></i>权限</a>
                            }
                            @if ((bool)ViewData[PageCode.PAGE_Button_Delete])
                            {
                                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                            }
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="~/layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table'], function () {
            var $ = layui.$,
                form = layui.form,
                table = layui.table;

            table.render({
                elem: '#app-table'
                , url: '/Role/GetList'
                //,where: {token: 'sasasas', id: 123 } //如果无需传递额外参数，可不加该参数
                //,method: 'post' //如果无需自定义HTTP类型，可不加该参数
                , response: {
                    statusName: 'code' //规定数据状态的字段名称，默认：code
                    , statusCode: '1000 ' //规定成功的状态码，默认：0
                    , msgName: 'msg' //规定状态信息的字段名称，默认：msg
                    , countName: 'count' //规定数据总数的字段名称，默认：count
                    , dataName: 'data' //规定数据列表的字段名称，默认：data
                }
                , cols: [[                    
                      { field: 'roleId', width: 80, title: 'ID' }
                    , { field: 'roleName', width: 200, title: '角色名称' }
                    , { field: 'description', width: '40%', title: '描述' }
                    , { align: 'center', field: 'isActive', width: 100, title: '状态', minWidth: 200, templet: '#status' }                  
                    , { align: 'center', fixed: 'right', toolbar: '#app-table-bar' }
                ]]
                , request: {
                    pageName: 'pageIndex' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                , page: true
            });

            //监听表格复选框选择
            table.on('checkbox(app-table)', function (obj) {
                console.log(obj)
            });
            //监听工具条
            table.on('tool(app-table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm("确认删除?", function (index) {
                        var loading = layer.load(0, {
                            shade: 0.3
                        });
                        $.ajax({
                            url: "/Role/Delete",
                            data: { 'id': data.roleId },
                            type: "post",
                            dataType: "json",
                            success: function (res) {
                                console.log(res);
                                layer.close(loading);
                                if (res.code == 1000) {
                                    layer.msg(res.msg);
                                    obj.del();
                                    layer.close(index);
                                    //location.reload('#app-table'); //删除成功后再刷新
                                }
                                else {
                                    layer.msg(res.msg);
                                }
                            }
                        });
                    });
                } else if (obj.event === 'edit') {
                    console.log(data);
                    window.location.href = '/role/edit/' + data.roleId;
                } else if (obj.event === 'autho') {                
                    window.location.href = '/role/authorize/' + data.roleId;
                }
            });

            //监听搜索
            form.on('submit(app-search)', function (data) {
                var field = data.field;

                //执行重载
                table.reload('app-table', {
                    where: field
                });
            });
        });
    </script>
</body>
</html>